package com.imooc.bilibili.controller;

import com.imooc.bilibili.annotation.ApiLimitedRoleAnnotation;
import com.imooc.bilibili.constant.AuthRoleConstant;
import com.imooc.bilibili.entity.UserMoments;
import com.imooc.bilibili.result.Result;
import com.imooc.bilibili.service.UserMomentService;
import com.imooc.bilibili.support.UserSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user_moment")
public class UserMomentController {

    @Autowired
    private UserMomentService userMomentService;

    @Autowired
    private UserSupport userSupport;


    /**
     * 用户发布动态
     */
    @ApiLimitedRoleAnnotation(limitedRoleCodeList = {AuthRoleConstant.ROLE_CODE_LV0})
    @PostMapping("/insert-user-moments")
    public Result<String> insertUserMoments(@RequestBody UserMoments userMoments) throws Exception {
        Long userId = userSupport.getCurrnetUserId().get("userId");
        userMoments.setUserId(userId);
        userMomentService.insertUserMomentsService(userMoments);
        return Result.success();
    }

    /**
     * 查询用户动态
     */
    @GetMapping("/user-subscribed-moments")
    public Result<List<UserMoments>> queryUserSubscribedMoments() throws Exception {
        Long userId = userSupport.getCurrnetUserId().get("userId");
        List<UserMoments> list = userMomentService.queryUserSubscribeMomentsService(userId);
        return new Result<>(list);
    }
}
